<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Bootstrap</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">

  <style>
    .modal-header {
      background-color: rgb(239, 243, 246)
    }
    .modal-header .modal-title  {
      margin-left: 180px;
    }
    .modal-body span {
      display: block;
      font-size: 16px;
      margin-left: 15px;
      margin-bottom: 6px;
    }
    .modal-body input {
      display: block;
      height: 30px;
      width: 420px;
      font-size: 14px;
      border-radius: 5px;
      margin-left: 15px;
      padding-left: 8px;
      border: 1px solid black;
      outline: none;
    }
    .space {
      margin-top: 20px;
    }
    .btn-secondary {
      width: 100px;
      margin-right: 60px;
    }
    .btn-primary {
      width: 100px;
      margin-right: 105px;
    }

  </style>
</head>
<body>

  <!-- data-bs-toggle="modal" 绑定弹窗 -->
  <!-- data-bs-target=".my-box" 具体哪个弹窗 -->
  <button class="button" data-bs-toggle="modal" data-bs-target=".my" >显示弹框</button>

  <!-- 复制代码 -->
  <div class="modal my" tabindex="-1">
  <div class="modal-dialog">

    <!-- 弹窗内容 -->
    <div class="modal-content">

      <!-- 弹窗头部 -->
      <div class="modal-header">
        <h4 class="modal-title">新增部门</h4>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>

      <!-- 弹窗身体 -->
      <div class="modal-body">
        <form action="">
          <span>部门名称</span>
          <input type="text">
          <span class="space">部门负责人</span>
          <input type="text">
          <span class="space">联系电话</span>
          <input type="text">
        </form>
      </div>

      <!-- 弹窗底部 -->
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary">保存</button>
      </div>


    </div>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" ></script>
<script>
  const modalDom = document.querySelector('.my')
  const modal = new bootstrap.Modal(modalDom)

  document.querySelector('.button').addEventListener('click',() => {

    // 显示弹窗
    modal.show()
  })

  document.querySelector('.btn-primary').addEventListener('click',() => {
    
    // 隐藏弹窗
    modal.hide()
  })

</script>

</body>
</html>